package fregat.connector.worker;

import fregat.base.util.ConfigurationBundle;
import fregat.connector.ConnectorService;

/**
 * Worker that transfers data from one channel to an other channel.
 *
 * @author Alexander Mann <br><b><i>ECO_L O G</i> &nbsp Logistiksysteme GmbH</b>
 * @version 1.0
 */
public class TransferWorker extends DefaultWorker {
  private String inChannel;
  private String outChannel;

  public TransferWorker(String name) {
    super(name);

    ConfigurationBundle configuration = ConnectorService.getConfiguration();
    String configPath = "worker.config." + getName() + ".channel";

    inChannel = configuration.getConfigurationString(configPath + ".in");
    outChannel = configuration.getConfigurationString(configPath + ".out");
  }

  protected boolean dataReceived(String channelName, String receivedData) {
    super.dataReceived(channelName, receivedData);

    if (channelName.equals(inChannel)) {
      channelName = outChannel;
    } else {
      channelName = inChannel;
    }
    return send(channelName, receivedData);
  }
}
